package com.bristua.mall.user.biz;

import com.bristua.mall.common.utils.CacheUtil;
import com.bristua.mall.user.dao.CountUserConsumptionRecordMapper;
import com.bristua.mall.user.dao.TUserAccountMapper;
import com.bristua.mall.user.model.TUser;
import com.bristua.mall.user.model.TUserAccount;
import com.bristua.mall.user.model.condition.TUserAccountExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/3/27.
 */
@Service
public class QueryUserConsumptionRecordBiz {

    @Resource
    private CountUserConsumptionRecordMapper countUserConsumptionRecordMapper;

    @Resource
    private TUserAccountMapper tUserAccountMapper;

    @Autowired
    private CacheUtil cacheUtil;

    public Map<String,Object> queryUserConsumptionRecord(){
        Map<String,Object> data = new HashMap();

        TUser userSession = (TUser) cacheUtil.getUserSession();

        String userId =userSession.getUserId();

        TUserAccountExample tUserAccountExample = new TUserAccountExample();
        tUserAccountExample.createCriteria().andUserIdEqualTo(userId);
        List<TUserAccount> tUserAccounts = tUserAccountMapper.selectByExample(tUserAccountExample);
        if(tUserAccounts!=null && tUserAccounts.size()>0){
            TUserAccount tUserAccount = tUserAccounts.get(0);
            data.put("integral",tUserAccount.getUserIntegral());
        }else{
            data.put("integral","0");
        }
        Integer integer = countUserConsumptionRecordMapper.countuserConsumptionRecord(userId);
        data.put("totalConsumeAmt", integer ==null?0:integer);
        data.put("inviteCode", userSession.getUserCode());
        return data;
    }
}
